package org.orbis.spikezolt;

import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import android.graphics.Color;
import android.graphics.Typeface;

public class TextureManager {
	private SpikeZoltActivity sa;
	public BitmapTextureAtlas blockTextureAtlas, playerTextureAtlas,
			endTextureAtlas, switchTextureAtlas;
	public BitmapTextureAtlas bFontTexture, wFontTexture;
	public TextureRegion TR_blockRed, TR_blockBlue, TR_blockPurple;
	public TextureRegion TR_endLow, TR_endTop, TR_endGlass;
	public TiledTextureRegion TR_player;
	public TiledTextureRegion TR_redSwitch, TR_blueSwitch, TR_purpleSwitch;

	public BitmapTextureAtlas tutorialTextureAtlas;
	public TextureRegion TR_pedestal, TR_qball, TR_cloud;

	public Font bFont, wFont;

	public TextureManager(SpikeZoltActivity sa) {
		this.sa = sa;
		// TEXTUREATLAS'
		blockTextureAtlas = new BitmapTextureAtlas(64, 16,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);

		playerTextureAtlas = new BitmapTextureAtlas(512, 512,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);

		switchTextureAtlas = new BitmapTextureAtlas(128, 16,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);

		endTextureAtlas = new BitmapTextureAtlas(512, 512,
				TextureOptions.REPEATING_BILINEAR_PREMULTIPLYALPHA);

		tutorialTextureAtlas = new BitmapTextureAtlas(512, 128,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		// TEXTURE REGIONS AND TILED TEXTURE REGIONS
		TR_pedestal = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				tutorialTextureAtlas, sa, "gfx/pedestal.png", 0, 0);
		TR_qball = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				tutorialTextureAtlas, sa, "gfx/questionBall.png", 32, 0);

		TR_cloud = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				tutorialTextureAtlas, sa, "gfx/textCloud.png", 53, 0);

		TR_player = BitmapTextureAtlasTextureRegionFactory
				.createTiledFromAsset(playerTextureAtlas, sa,
						"gfx/spikeSheet.png", 0, 0, 4, 3);

		TR_endLow = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				endTextureAtlas, sa, "gfx/endBottom.png", 0, 0);
		TR_endTop = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				endTextureAtlas, sa, "gfx/endTop.png", 0, 64);

		TR_endGlass = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				endTextureAtlas, sa, "gfx/endGlass.png", 0, 128);

		TR_blockRed = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				blockTextureAtlas, sa, "gfx/redBlock.png", 0, 0);
		TR_blockBlue = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				blockTextureAtlas, sa, "gfx/blueBlock.png", 16, 0);
		TR_blockPurple = BitmapTextureAtlasTextureRegionFactory
				.createFromAsset(blockTextureAtlas, sa, "gfx/purpleBlock.png",
						32, 0);

		TR_redSwitch = BitmapTextureAtlasTextureRegionFactory
				.createTiledFromAsset(switchTextureAtlas, sa,
						"gfx/redSwitchSheet.png", 0, 0, 2, 1);
		
		TR_blueSwitch = BitmapTextureAtlasTextureRegionFactory
				.createTiledFromAsset(switchTextureAtlas, sa,
						"gfx/blueSwitchSheet.png", 52, 0, 2, 1);

		TR_purpleSwitch = BitmapTextureAtlasTextureRegionFactory
				.createTiledFromAsset(switchTextureAtlas, sa,
						"gfx/purpleSwitchSheet.png", 78, 0, 2, 1);


		bFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR);
		wFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR);

		// LOAD TEXTURE ATLAS'
		sa.mEngine.getTextureManager().loadTextures(blockTextureAtlas,
				playerTextureAtlas, endTextureAtlas, switchTextureAtlas,
				tutorialTextureAtlas);
		sa.mEngine.getTextureManager().loadTexture(bFontTexture);
		sa.mEngine.getTextureManager().loadTexture(wFontTexture);

		// LOAD FONTS
		final int fontSize = 11;
		bFont = new Font(bFontTexture, Typeface.create(Typeface.SANS_SERIF,
				Typeface.BOLD), fontSize, true, Color.BLACK);
		wFont = new Font(wFontTexture, Typeface.create(Typeface.DEFAULT,
				Typeface.BOLD), fontSize, true, Color.WHITE);
		sa.mEngine.getFontManager().loadFont(bFont);
		sa.mEngine.getFontManager().loadFont(wFont);

	}
}
